//计划任务
// const Adpro = {
//     /**
//      * 登陆接口
//      * @param data
//      * @param url
//      * @returns {Promise<any>}
//      */
//     login: function () {
//         return axios({
//             url: '/rbac/data/LandInfo/getList',
//             headers: {
//                 Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyTGV2ZWwiOjEsImFkbWluaXN0cmF0aXZlQ29kZSI6IjQ0MDYwNSIsInVzZXJfaWQiOjEsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsiYWxsIl0sImxvZ2luTmFtZSI6ImFkbWluIiwiVXNlcklkZW50aXR5IjpbIuWMuue6p-S_oeaBr-WRmCJdLCJleHAiOjE2NTc0NzU1NzYsImF1dGhvcml0aWVzIjpbIm1lbWJlcjptZW1iZXI6dXBkYXRlTWVtYmVyUGFzc3dvcmQiLCJnb29kczpnb29kczphZGRHb29kc0NhdGVnb3J5IiwiZ29vZHM6Z29vZHM6ZGVsZXRlR29vZHNDYXRlZ29yeSIsImdvb2RzOmdvb2RzOmFkZEdvb2RzQnJhbmQiLCJzbXM6c3lzbm90aWNlcmVjb3JkczpsaXN0Iiwic3lzOmNvbmZpZzpzYXZlIiwic3lzOmNvbmZpZzp1cGRhdGUiLCJnb29kczpnb29kczpnZXRTcGVjQW5kQnJhbmtMaXN0IiwiZ29vZHM6Z29vZHM6R29vZHNDcmVhdGVPclVwZGF0ZSIsIm1lbWJlcjptZW1iZXI6dXBkYXRlQ3VzdG9tZXJTZXJ2aWNlIiwiZ29vZHM6Z29vZHM6dXBkYXRlR29vZHNBdHRyaWJ1dGUiLCJzbXM6c3lzbm90aWNldGVtcGxhdGU6bGlzdCIsInN5czpyb2xlOmxpc3QiLCJtZW1iZXI6bWVtYmVycGFydG5lcjphdWRpdG9yIiwic3lzOm1lbnU6c2VsZWN0Iiwic3VwcGxpZXI6c3VwcGxpZXI6bGlzdCIsInN5czpzY2hlZHVsZTp1cGRhdGUiLCJzeXM6c2NoZWR1bGU6c2F2ZSI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bWJlcjpwb2ludGxpc3QiLCJnb29kczpnb29kczp1cGRhdGVHb29kc0dyb3VwIiwic3lzOnVzZXI6aW5mbyIsInN5czpjb25maWc6ZGVsZXRlIiwic3lzOnNjaGVkdWxlOnJ1biIsInNtczpzeXNub3RpY2V0ZW1wbGF0ZTpzYXZlIiwic3VwcGxpZXI6c3VwcGxpZXI6ZGVsZXRlIiwic3lzOnJvbGU6ZGVsZXRlIiwibWVtYmVyOm1lbWJlcjpiYWxhbmNlTWVtYmVyQWNjb3VudCIsIm1lbWJlcjptZW1iZXI6dXBkYXRlTWVtYmVyTGV2ZWwiLCJzdXBwbGllcjpzdXBwbGllcjpzYXZlIiwiZ29vZHM6Z29vZHM6ZGVsZXRlR29vZHMiLCJtZW1iZXI6bWVtYmVyOm1lbWJlckxldmVsTGlzdCIsInN5czpzY2hlZHVsZTpwYXVzZSIsImdvb2RzOmdvb2RzOnJlcGx5RXZhbHVhdGVBamF4Iiwic3lzOmxvZzpsaXN0Il0sImp0aSI6IjFlZTIxY2IyLTJiZWEtNGY1OC1hZGU5LTUzODA4MWZkNWFhOSIsImNsaWVudF9pZCI6ImNsaWVudCJ9.Kfz2mUzFhFh9vKfAI6dwymzw3Cav_UJTArxY30ZcdB4"
//             }
//         }).then(function (res) { 
//            const news=res.data.list  
           
//             return Promise.resolve(res)
//         }).catch(function (err) {
//             console.log(err.txt+1)
//         })
//     },
   
// }
// Adpro.login()
let arrss = Mock.mock({
    "list|80": [
        {  
            "landCode": '@natural(100, 999)',
            "id|+1": 29016,
            "landName": '@ctitle(3)'+"塘",
            "landPlans": '@ctitle(5)'+'@natural(10000000, 99999999)',
            "landTownName": '@ctitle(3)'+"镇",
            "landVillageName": '@ctitle(2)'+'-'+'@ctitle(2)'+"-"+'@ctitle(2)',
            "mu":'@float(60, 100, 3, 5)',
            "landTypeName":'@ctitle(3)',
           "landProductName":'@ctitle(3)',
           "subjectNames":'@cname',
           "landTypeName1":'@ctitle(3)'+"塘",
           "landTypeName2":'@ctitle(3)'+"塘",
           "landTypeName3":'@ctitle(3)'+"塘"
        }
    ]
})
let pro2 = Mock.mock({
    "list|60": [
        {  
            "landCode": '@natural(100, 999)',
            "id|+1": 29016,
            "landName": '@ctitle(3)'+"塘",
            "landPlans": '@ctitle(5)'+'@natural(10000000, 99999999)',
            "landTownName": '@ctitle(3)'+"镇",
            "landVillageName": '@ctitle(2)'+'-'+'@ctitle(2)'+"-"+'@ctitle(2)',
            "mu":'@float(60, 100, 3, 5)',
            "landTypeName":'@ctitle(3)',
           "landProductName":'@ctitle(3)',
           "subjectNames":'@cname',
           "landTypeName":'@ctitle(3)'+"塘"
        }
    ]
})
let news = pro2.list
var that         
class BiaoDan {
    constructor(id,yeshu,array) {
        that = this
        this.main = document.querySelector(id)
        this.tbody = this.main.querySelector('tbody')
        this.news = array
        this.init(yeshu)
    }
    init(qqq) {
        this.fenye(qqq)
        this.sle()
    }
    sle(){
        this.sel=this.main.querySelector('select')
        this.sel.onclick=(e)=>{
            e.stopPropagation()
            this.main.querySelector(".page ul").innerHTML=''
            let index = this.sel.selectedIndex;
            this.fenye(this.sel.options[index].value) 
        }
    }
    getNode(){
        this.oul=this.main.querySelector(".page ul")
        this.nextPage = this.main.querySelector('.nextPage')
        this.beforePage = this.main.querySelector('.beforePage')
        this.lastPage = this.main.querySelector('.lastPage')
    }
    // 1.导入数据
    // 2 分页功能
    fenye(page){
        that.getNode()
        function daoru(arr) {
            if (typeof arr === "undefined") {
                arr = that.news.slice();
                arr.length = page
            }
            that.tbody.innerHTML = ''
            function arrr() {
                 arr.forEach(function (item) {
                that.tbody.insertAdjacentHTML('beforeEnd',`<tr>
                <td>${item.landCode}</td>
                <td>${item.landName }</td>
                <td>${item.landTownName }</td>
                <td>${item.landVillageName }</td>
                <td>${item.mu}</td>
                <td>${item.landTypeName }</td>
                <td>${item.landProductName }</td>
                <td>${item.subjectNames}</td>    
                <td><div class="btn-group ">
                <button type="button" class="btn btn-sm btn-default amend">
                <span class="glyphicon glyphicon-pencil" > </span>
                </button>
                <button type="button" class="delet btn btn-sm btn-default">
                <span class="glyphicon glyphicon-trash" > </span>
                </button>
                <button type="button" class="sure btn btn-sm btn-default" style="display:none;">
                <span class="glyphicon glyphicon-ok" > </span>
                </button>
                <button type="button" class="back btn btn-sm btn-default" style="display:none;">
                <span class="glyphicon glyphicon-remove" > </span>
                </button>
                </div></td>
            </tr>`)
        })
            }
         arrr()
           
    }
    daoru()
        let a =1
        function changePage(x, y) {
            let item = that.news.slice((x) * page, +(y) * page)
            daoru(item)
        }
        for (let index = 0; index < that.news.length / page; index++) {
            let oSpan = document.createElement('li');
            oSpan.classList='btn btn-info'
            oSpan.innerHTML = index + 1;       
            oSpan.onclick = function () {
                changePage(this.innerHTML - 1, this.innerHTML)
                a = this.innerHTML
            }        
            that.oul.appendChild(oSpan)
        }
        that.nextPage.onclick = function () {
            if (a == Math.ceil(that.news.length / page)) {
                return 0
            }
            changePage(a, a + 1)
            a++
        }
        that.beforePage.onclick = function () {
            if (a == 1) {
                return 0
            }
            changePage(a - 2, a - 1)
            a--
        }
        that.lastPage.onclick = function () {
            if (that.lastPage.textContent == '最后一页') {
                that.lastPage.textContent = '第一页'
                changePage(Math.ceil(that.news.length / page)-1, Math.ceil(news.length / page))
                a = 4
            } else {
                that.lastPage.textContent = '最后一页'
                changePage(0, 1)
                a = 1
            }
        }
    }
    
}

var _that
 new BiaoDan(".showone",10,news)
   class BiaoDan2 {
    constructor(id,yeshu,array) {
        _that = this
        this.main = document.querySelector(id)
        this.tbody = this.main.querySelector('tbody')
        this.news = array
        this.init(yeshu)
    }
    init(qqq) {
        this.fenye(qqq)
        this.sle()
    }
    sle(){
        this.sel=this.main.querySelector('select')
        this.sel.onclick=(e)=>{
            e.stopPropagation()
            this.main.querySelector(".page ul").innerHTML=''
            let index = this.sel.selectedIndex;
            this.fenye(this.sel.options[index].value) 
        }
    }
    getNode(){
        this.oul=this.main.querySelector(".page ul")
        this.nextPage = this.main.querySelector('.nextPage')
        this.beforePage = this.main.querySelector('.beforePage')
        this.lastPage = this.main.querySelector('.lastPage')
    }
    // 1.导入数据
    // 2 分页功能
    fenye(page){
        _that.getNode()
        function daoru(arr) {
            if (typeof arr === "undefined") {
                arr = _that.news.slice();
                arr.length = page
            }
            _that.tbody.innerHTML = ''      
                 arr.forEach(function (item) {
                _that.tbody.insertAdjacentHTML('beforeEnd',`<tr>
                <td>${item.landCode}</td>
                <td>${item.landName }</td>
                <td>${item.landTownName }</td>
                <td>${item.landVillageName }</td>
                <td>${item.mu}</td>
                <td>${item.landTypeName }</td>
                <td>${item.landTypeName1 }</td>   
                <td>${item.landTypeName2 }</td>   
                <td>${item.landTypeName3}</td>   
                <td><div class="btn-group ">
                <button type="button" class="btn btn-sm btn-default amend">
                <span class="glyphicon glyphicon-pencil" > </span>
                </button>
                <button type="button" class="delet btn btn-sm btn-default">
                <span class="glyphicon glyphicon-trash" > </span>
                </button>
                <button type="button" class="sure btn btn-sm btn-default" style="display:none;">
                <span class="glyphicon glyphicon-ok" > </span>
                </button>
                <button type="button" class="back btn btn-sm btn-default" style="display:none;">
                <span class="glyphicon glyphicon-remove" > </span>
                </button>
                </div></td>
            </tr>`)
        })
            
           
    }
    daoru()
        let a =1
        function changePage(x, y) {
            let item = _that.news.slice((x) * page, +(y) * page)
            daoru(item)
        }
        for (let index = 0; index < _that.news.length / page; index++) {
            let oSpan = document.createElement('li');
            oSpan.classList='btn btn-info'
            oSpan.innerHTML = index + 1;       
            oSpan.onclick = function () {
                changePage(this.innerHTML - 1, this.innerHTML)
                a = this.innerHTML
            }        
            _that.oul.appendChild(oSpan)
        }
        _that.nextPage.onclick = function () {
            if (a == Math.ceil(_that.news.length / page)) {
                return 0
            }
            changePage(a, a + 1)
            a++
        }
        _that.beforePage.onclick = function () {
            if (a == 1) {
                return 0
            }
            changePage(a - 2, a - 1)
            a--
        }
        _that.lastPage.onclick = function () {
            if (_that.lastPage.textContent == '最后一页') {
                _that.lastPage.textContent = '第一页'
                changePage(Math.ceil(_that.news.length / page)-1, Math.ceil(_that.news.length / page))
                a = 4
            } else {
                _that.lastPage.textContent = '最后一页'
                changePage(0, 1)
                a = 1
            }
        }
    }
    
}
new BiaoDan2(".showtwo",10,arrss.list)
tables('#mytable')
tables('#mytable2')
// 表单功能
function tables(x, y) {
    var _this
    class Tab {
        constructor(id) {
            _this = this
            this.main = document.querySelector(id);
            this.tbody = this.main.querySelector('tbody');
            this.addTabs = this.main.querySelector('.addTab')
            this.init()
        }
        init() {
            if (this.addTabs = this.main.querySelector('.addTab')) {
                this.addTab()
            }
            this.updateNode()
            this.removeTab()
            this.editTab()
        }
        //1.获取节点
        updateNode() {
            this.tr = this.tbody.querySelectorAll('tr')
            this.amend = this.main.querySelectorAll('.amend')
            this.delet = this.main.querySelectorAll('.delet')
            this.sure = this.main.querySelectorAll('.sure')
            this.back = this.main.querySelectorAll('.back')
        }  
        //2.添加功能
        addTab() {
            this.addTabs.addEventListener('click', function () {
                _this.tbody.insertAdjacentHTML('beforeBegin', y)
                _this.updateNode()
                _this.removeTab()
                _this.editTab()
            })

        }
        //3.删除功能
        removeTab() {
            this.updateNode()
            this.delet.forEach(function (item) {
                item.addEventListener('click', function () {
                    item.parentNode.parentNode.parentNode.remove()
                })
            })

        }
        //4.修改功能
        editTab() {
            this.updateNode()
            let arr = []
            this.amend.forEach(function (item) {
                item.onclick = function () {
                    let tds = this.parentNode.parentNode.parentNode.children
                    $(this).hide().siblings().hide();
                    $(this).siblings(".sure").show()
                    $(this).siblings(".back").show()
                    for (let i = 0; i < tds.length; i++) {
                        if (i != 0 && i != tds.length - 1) {
                            let str = tds[i].textContent
                            arr.push(str)
                            tds[i].innerHTML = `<input type="text" class="form-control" value="${str}">`
                           // let input = _this.main.querySelector('.input')
                           
                        }
                    }
                }
            })
            //确定功能
            _this.sure.forEach(function (item) {
                item.addEventListener('click', function () {
                    let tds = this.parentNode.parentNode.parentNode.children
                    $(this).hide().siblings().hide();
                    $(this).siblings(".amend").show()
                    $(this).siblings(".delet").show()
                    for (let i = 0; i < tds.length; i++) {
                        if (i != 0 && i != tds.length - 1) {
                            let str = tds[i].children[0].value
                            tds[i].innerHTML = str
                            arr.push(str)
                        }
                    }
                })
            })
            //取消功能
            this.back.forEach(function (item) {
                item.addEventListener('click', function () {
                    let tds = this.parentNode.parentNode.parentNode.children
                    $(this).hide().siblings().hide();
                    $(this).siblings(".amend").show()
                    $(this).siblings(".delet").show()
                    for (let i = 0; i < tds.length; i++) {
                        if (i != 0 && i != tds.length - 1) {
                            tds[i].innerHTML = ''
                            tds[i].innerHTML = arr[i - 1]
                        }
                    }
                })
            })

        }
    }
    new Tab(x)
}



